01. Intro to Pseudoclassical Subclasses

Intro to Pseudoclassical Subclasses

Question:

Start Quiz:

var Car = function(loc){
    this.loc = loc;
};

// Your code goes here!

var zed = new Car(3);
zed.move();

// These lines have been commented out because Van hasn't been defined in this example
/*
var amy = new Van(9);
amy.move();
amy.grab();
*/
var acura = new Car();

describe("TEST: The Car class should be able to move.", function() {
    it("Car can move: ", function() {
    expect(Car).to.respondTo('move');
  });
});

describe("TEST: new Cars should be able to move.", function() {
    it("new Cars can move: ", function() {
    expect(acura).to.respondTo('move');
  });
});

describe("TEST: new Cars should not have their own move methods.", function() {
    it("The move method falls through new Car objects: ", function() {
    expect(acura).not.to.have.ownProperty('move');
  });
});

User's Answer:

(Note: The answer done by the user is not guaranteed to be correct)

var Car = function(loc){
    this.loc = loc;
};

// Your code goes here!
Car.prototype.move = function() {
    ;
}

var zed = new Car(3);
zed.move();

// These lines have been commented out because Van hasn't been defined in this example
/*
var amy = new Van(9);
amy.move();
amy.grab();
*/
var acura = new Car();

describe("TEST: The Car class should be able to move.", function() {
    it("Car can move: ", function() {
    expect(Car).to.respondTo('move');
  });
});

describe("TEST: new Cars should be able to move.", function() {
    it("new Cars can move: ", function() {
    expect(acura).to.respondTo('move');
  });
});

describe("TEST: new Cars should not have their own move methods.", function() {
    it("The move method falls through new Car objects: ", function() {
    expect(acura).not.to.have.ownProperty('move');
  });
});
Solution: